<div class="tablenav">
<form method="get" id="photos" action="<?php echo (ereg('media-upload.php', $_SERVER['REQUEST_URI']) ? 'media-upload.php' : 'upload.php');?>">
<input type="hidden" name="tab" value="<?php echo $_GET['tab'];?>" />
<input type="hidden" name="post_id" value="<?php echo $_GET['post_id'];?>" />
<input type="hidden" name="action" value="<?php echo $_GET['action'];?>" />
<input type="hidden" name="style" value="<?php echo $_GET['style'];?>" />
<input type="hidden" name="_wpnonce" value="<?php echo $_GET['_wpnonce'];?>" />
<input type="hidden" name="ID" value="<?php echo $_GET['ID'];?>" />

<input type="submit" name="refresh" value="refresh albums" />
</form>
</div>

<?php if (count($albums) == 0):?>
Sorry, no albums found!
<?php elseif (is_array($albums)):
$baseurl = get_option('silas_flickr_baseurl');
$linkoptions = get_option('silas_flickr_linkoptions');
$parts = parse_url(get_bloginfo('home'));
$home = 'http://'.$parts['host'];
$json = new Services_JSON();
$photoJSONs = array();
?>
<ul id='upload-files'>
<?php 
$id = 0;
$hasShortCode = function_exists('add_shortcode');
foreach ($albums as $album):
if ($baseurl && !$everyone && ($linkoptions != 'flickr')) {
    $album['targetURL'] = $home.$baseurl.'album/'.$album['id'].'/'.$album['pagename'];
} else {
	$album['targetURL'] = 'http://www.flickr.com/photos/'.$user['user']['nsid'].'/sets/'.$album['id'].'/';
}
$photoJSONs[] = $json->encode($album);
?>
<li id='flickr-photo-<?php echo $id?>' class='alignleft'>
<a 
	id="file-link-<?php echo $id?>"
	href="<?php echo $album['targetURL']?>" 
	title="<?php echo htmlentities($album['title'], ENT_QUOTES, 'UTF-8');?>" 
	onclick="return false"
	class="file-link photo"><img 
    	id="photo-<?php echo $id?>" 
    	src="<?php echo $album['sizes']['Square']['source']?>" 
    	alt="<?php echo htmlentities($album['title'], ENT_QUOTES, 'UTF-8');?>" 
    	height="<?php echo $album['sizes']['Square']['height']?>" width="<?php echo $album['sizes']['Square']['width']?>" 
    	/></a>
</li>
<?php 
$id++;
endforeach;?>
</ul>
<div class="photo-options" id="photo-meta"></div>
<?php /*  // TODO: Browse photos in album
<div class="photo-options" id="album-tabs">
<a href="#" id="tab-album-insert" class="selected">Insert Album</a>
<a href="#" id="tab-album-photos">Browse Album Photos</a>
</div>
*/ ?>
<div class="photo-options" id="album-insert">
<form>
<input type="hidden" name="photo-id" id="photo-id" value="" />
<table class="describe album">
<tbody>
<tr class="image-size album-insert-photos">
    <th class="label" valign="top" scope="row"><label>Photos</label></th>
    <td class="field">
    <input type="radio" name="album-insert-photos" id="album-insert-cover"  value="cover" checked="checked"><label for="album-insert-cover"> Album cover</label>
    
	<input type="radio" name="album-insert-photos" id="album-insert-5"  value="5"><label for="album-insert-5"> 5 photos</label>
	<input type="radio" name="album-insert-photos" id="album-insert-10" value="10"><label for="album-insert-10"> 10 photos</label>
	<input type="radio" name="album-insert-photos" id="album-insert-20" value="20"><label for="album-insert-20"> 20 photos</label>
	<input type="radio" name="album-insert-photos" id="album-insert-30" value="30"><label for="album-insert-30"> 30 photos</label>
    </td>
</tr>
<tr class="image-size">
    <th class="label" valign="top" scope="row"><label>Size</label></th>
    <td class="field">
		<input name="album-image-size" id="album-image-size-square" value="Square" type="radio">
		<label for="album-image-size-square">Square</label>
		<input name="album-image-size" id="album-image-size-thumb" value="Thumbnail" type="radio" checked="checked">
		<label for="album-image-size-thumb">Thumbnail</label>
		<input name="album-image-size" id="album-image-size-medium" value="Medium" type="radio">
		<label for="album-image-size-medium">Medium</label>
		<input name="album-image-size" id="album-image-size-large" value="Large" type="radio">
		<label for="album-image-size-large">Large</label>
		<input name="album-image-size" id="album-image-size-original" value="Original" type="radio">
		<label for="album-image-size-original">Original</label>    
    </td></tr>
<tr class="submit">
    <td>&nbsp;</td>
    <td class="savesend">
        <input type="button" value="Insert into Post" name="send" class="button send"/> 
        <input type="button" value="Cancel" name="cancel" class="button cancel"/> 
        &nbsp; &nbsp;
        <label for="image-close-check" id="image-close"><input type="checkbox" id="image-close-check" name="image-close-check" value="1" checked="checked" /> close after inserting photo</label> 
        </td></tr>
        
</tbody>

</table>
</form>
</div>
<?php /*
<div class="photo-options" id="album-photos">
</div>
*/ ?>


<script type="text/javascript">
var photos = [<?php echo implode(',', $photoJSONs);?>];
</script>
<?php endif; ?>
